<template>
  <el-dialog :visible.sync="isShow" width="1000px" :title='title' append-to-body>
    <el-form ref="rowForm" :model="rowForm" :rules="rules" label-position="top" style="margin-top: 20px;">
      <el-row :gutter="20" style="display: flex;flex-direction: row;flex-wrap: wrap;">
        <el-col :span="24">
          <el-form-item label="父级章节" prop="name">
            {{ rowForm.parentName || '无' }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="章节名称" prop="name">
            <el-input v-model="rowForm.name" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="标题" prop="name">
            <el-input v-model="rowForm.title" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="排序" prop="sort">
            <el-input v-model="rowForm.sort" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div style="margin-top: 30px;width: 100%;display: flex;flex-direction: row;justify-content: flex-end;">
      <el-button type="primary" @click="submitForm('rowForm')">保存</el-button>
      <el-button @click="close" type="info" size="mini">关闭</el-button>
    </div>

  </el-dialog>
</template>

<script>
import { Loading } from 'element-ui';
export default {
  components: {
  },
  props: {
  },
  data() {
    return {
      isShow: false,
      fullscreenLoading: null,
      rowForm: {},
      rowData: {},
      rules: {},
      title: '',
      formData: {},
      courseId: ''
    }
  },
  created() {

  },
  methods: {
    show(val) {
      this.isShow = true
      this.formData = val.formData
      this.rowForm = val.row
      this.courseId = val.courseId
    },
    close() {
      this.isShow = false
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.fullscreenLoading = Loading.service({ fullscreen: true, text: '正在保存，请稍后！' });
          if (this.rowForm.id) {
            this.rowForm.obj_id = this.rowForm.id
            this.rowForm.course = this.courseId
            this.request_post(this.formData.updateUrl, this.rowForm).then(res => {
              this.fullscreenLoading.close()
              if (res.data.code == 10000) {
                this.close()
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
              }
            })
          } else {
            this.rowForm.course = this.courseId
            this.request_post(this.formData.createUrl, this.rowForm).then(res => {
              this.fullscreenLoading.close()
              if (res.data.code == 10000) {
                this.close()
                this.$emit("confirm")
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
              }
            })
          }

        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>